window.onload=function(){
	//轮播和高度自适应	
	var img=document.querySelectorAll(".slider img"),
	ul_height=document.querySelector("#ul-height"),
	slideshow=document.querySelector(".slider"),
	index=0,
	length=img.length;
	
	//自动轮播
	var timer=setInterval(function(){
		img[index].style.opacity='0';
		index++;
		index=index%length;
		img[index].style.opacity='1';
	},8000)
	//停止动画
	slideshow.onmousemove=function(){
		clearInterval(timer);
	}
	//鼠标移开开始动画
	slideshow.onmouseout=function(){
		timer=setInterval(function(){
			img[index].style.opacity='0';
			index++;
			index=index%length;
			img[index].style.opacity='1';
		},8000)
	}
	ul_height.style.height=img[0].offsetHeight+"px";
}


//图片无限轮播
var id = function(el) {
		return document.getElementById(el);//返回id
	},
	c = id('join-photos');//得到ul
if(c){
	var ul = id('join-scroll'),
		lis = ul.getElementsByTagName('li'),
		itemCount = lis.length,//获取li的个数
		width = lis[0].offsetWidth, //获得每个img容器的宽度
		marquee = function() {
			c.scrollLeft +=2;
//			console.log(c.scrollLeft)
			if(c.scrollLeft % width <= 1) { //当 c.scrollLeft 和 width 相等时，把第一个img追加到最后面							
				ul.appendChild(ul.getElementsByTagName('li')[0]);
				c.scrollLeft = 0;
			};
		},
		speed =40; //数值越大越慢
	ul.style.width = width * itemCount + 'px'; //加载完后设置容器长度        
	var timer = setInterval(marquee, speed);
	c.onmouseover = function() {//鼠标移入停止
		clearInterval(timer);
	};
	c.onmouseout = function() {//鼠标移出开始
		timer = setInterval(marquee, speed);
	};
};